<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * default sync for model
 * @author yiminghe@gmail.com
 */
KISSY.add(&quot;mvc/sync&quot;, function (S, io, Json) {
    var methodMap = {
        'create': 'POST',
        'update': 'POST', //'PUT'
        'delete': 'POST', //'DELETE'
        'read': 'GET'
    };

<span id='KISSY-MVC-method-sync'>    /**
</span>     * Default sync mechanism.
     * Sync data with server using {@link KISSY.IO} .
     * @member KISSY.MVC
     * @param {KISSY.MVC.Model|KISSY.MVC.Collection} self Model or Collection instance to sync with server.
     * @param {String} method Create or update or delete or read.
     * @param {Object} options IO options
     */
    function sync(self, method, options) {
        var type = methodMap[method],
            ioParam = S.merge({
                type: type,
                dataType: 'json'
            }, options),
            data,
            url;

        data = ioParam.data = ioParam.data || {};
        data['_method'] = method;

        if (!ioParam.url) {
            url = self.get(&quot;url&quot;);
            ioParam.url = (typeof url == 'string') ?
                url :
                url.call(self);
        }

        if (method == 'create' || method == 'update') {
            data.model = Json.stringify(self.toJSON());
        }

        return io(ioParam);
    }

    return sync;
}, {
    requires: ['io', 'json']
});</pre>
</body>
</html>
